package xin.i18n.sample.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import xin.i18n.interceptor.LocaleChangeInterceptor;
import xin.i18n.starter.I18nProperties;
import xin.i18n.util.ResolverType;

/**
 * <pre>
 * test
 * </pre>
 *
 * @author lixin_ma@outlook.com
 * @version 1.0
 * @since 2019/12/5
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
	
	@Value("${i18n.interceptor.patterns}")
	private String patterns;
	
	@Value("${i18n.interceptor.type}")
	private ResolverType type;
	
	@Value("${i18n.interceptor.name}")
	private String name;
	
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor();
		interceptor.setProper(new I18nProperties.Interceptor().setName(name).setType(type));
		registry.addInterceptor(interceptor).addPathPatterns(patterns.split(","));
	}
}
